<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
        "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="${tableInfo.tableClassName?lower_case}">
    <resultMap id="BASE_${tableInfo.tableClassName?upper_case}_MAP" class="${packageName}.model.${tableInfo.tableClassName}">
    <#list tableInfo.tableColumns as columnInfo>
        <!--  ${columnInfo.remark}-->
        <result property="${columnInfo.javaName}" column="${columnInfo.jdbcName}" jdbcType="${columnInfo.ibatisJdbcType}"/>
    </#list>
    </resultMap>

    <!-- 不带条件的查询全部-->
    <select id="select${tableInfo.tableClassName}All" resultMap="BASE_${tableInfo.tableClassName?upper_case}_MAP">
        SELECT
    <#list tableInfo.tableColumns as columnInfo>
            ${columnInfo.jdbcName}<#if columnInfo_has_next>,</#if>
    </#list>
        FROM
        ${tableInfo.tableName}
    </select>

    <!--单表插入-->
    <insert id="insert${tableInfo.tableClassName}" parameterClass="${packageName}.model.${tableInfo.tableClassName}">
        INSERT INTO ${tableInfo.tableName}(
        <#list tableInfo.tableColumns as columnInfo>
            ${columnInfo.jdbcName}<#if columnInfo_has_next>,</#if>
        </#list>
        )
        VALUES (
        <#list tableInfo.tableColumns as columnInfo>
            #${columnInfo.javaName}:${columnInfo.ibatisJdbcType}#<#if columnInfo_has_next>,</#if>
        </#list>
        )
    </insert>

    <!-- 根据id更新-->
    <update id="update${tableInfo.tableClassName}" parameterClass="${packageName}.model.${tableInfo.tableClassName}">
        update ${tableInfo.tableName}
        <dynamic prepend="set">
        <#list tableInfo.tableColumns as columnInfo>
            <isPropertyAvailable property="${columnInfo.javaName}">
                <isNotEmpty property="${columnInfo.javaName}" prepend=",">
                ${columnInfo.jdbcName} = #${columnInfo.javaName}:${columnInfo.ibatisJdbcType}#
                </isNotEmpty>
            </isPropertyAvailable>
        </#list>
        </dynamic>
        WHERE ${tableInfo.tablePkInfo.jdbcName} =#${tableInfo.tablePkInfo.javaName}:${tableInfo.tablePkInfo.ibatisJdbcType}#
    </update>

    <!--根据id 批量删除-->
    <delete id="del${tableInfo.tableClassName}" parameterClass="java.util.List">
        DELETE FROM ${tableInfo.tableName}  WHERE  ${tableInfo.tablePk} in
        <iterate open="(" close=")" conjunction=",">
            #${tableInfo.tablePkInfo.javaName}s[]#
        </iterate>
    </delete>

</sqlMap>